import ICTCLAS.I3S.AC.ICTCLAS50;

public class POSTool {
	public static void POSFile(String fileName) {
		try {
			ICTCLAS50 testICTCLAS50 = new ICTCLAS50();
			String argu = ".";
			if (testICTCLAS50.ICTCLAS_Init(argu.getBytes("GB2312")) == false) {
				System.out.println("Init Fail!");
				return;
			}
			int index = fileName.indexOf(".txt");
			String out = fileName.substring(0, index) + "_pos.txt";
			testICTCLAS50.ICTCLAS_FileProcess(fileName.getBytes(), 0, 1, out.getBytes());
		} catch (Exception ex) {
			ex.printStackTrace();
		}

	}

	public static String SegmentSentence(String sInput) {
		String result = "";
		try {
			ICTCLAS50 testICTCLAS50 = new ICTCLAS50();
			String argu = ".";
			if (testICTCLAS50.ICTCLAS_Init(argu.getBytes("GB2312")) == false) {
				System.out.println("Init Fail!");
				return null;
			}
			testICTCLAS50.ICTCLAS_SetPOSmap(2);

			byte nativeBytes[] = testICTCLAS50.ICTCLAS_ParagraphProcess(sInput.getBytes("GB2312"), 0, 0);
			result = new String(nativeBytes, 0, nativeBytes.length, "GB2312");

		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public static String POSSentence(String sInput) {
		String result = "";
		try {
			ICTCLAS50 testICTCLAS50 = new ICTCLAS50();
			String argu = ".";
			if (testICTCLAS50.ICTCLAS_Init(argu.getBytes("GB2312")) == false) {
				System.out.println("Init Fail!");
				return null;
			}
			testICTCLAS50.ICTCLAS_SetPOSmap(2);

			byte nativeBytes[] = testICTCLAS50.ICTCLAS_ParagraphProcess(sInput.getBytes("GB2312"), 0, 1);
			String segment = new String(nativeBytes, 0, nativeBytes.length, "GB2312");
			String items[] = segment.split(" ");
			for (int i = 0; i < items.length; i++)
				result += items[i] + " ";

		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public static void main(String args[]) {
		// POSFile("F:/sample.txt");
		// String sentence = "我是中国人";
		// System.out.println("原始句子:" + sentence);
		// System.out.println("分词结果:" + SegmentSentence(sentence));
		// System.out.println("词性标注结果:" + POSSentence(sentence));
		System.out.println(POSSentence("明光村的公交车车站怎么走"));
		System.out.println(POSSentence("北京邮电大学的食堂饭好吃不好吃"));
		System.out.println(POSSentence("西土城路的遗址公园叫做什么名字"));
		System.out.println(POSSentence("教三楼什么时候搬家呢"));
		System.out.println(POSSentence("我想知道学院路上哪些学校是有计算机专业的呢"));
		System.out.println(POSSentence("离北邮最近的地铁站是什么站"));
	}
}
